{% extends "../../../layui/layouts/main.html" %}

{% block mainbody %}

<div id="menu-index">

    <script type="text/html" id="tool">
        <a class="layui-btn layui-btn-info layui-btn-xs" lay-event="watch">关注</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="unwatch">不关注</a>
    </script>

    {% include "_search.tpl" %}

    <div class="layui-card">
        <div class="layui-card-header yak-card-header">
            {{Header}}
        </div>
        <div class="layui-card-body">
            <table id="drug-table" lay-filter="drug-table-filter"></table>
        </div>
    </div>

</div>
{% endblock %}

{% block script %}
<script>
    layui.use(['grid', 'layarea', 'laydate'], function () {


        var statusinfo = function (data) {
            if (data.status == 2) {
                return "<a class='layui-btn layui-btn-success layui-btn-xs'>" + data.status_label + "</a>"
            }
            if (data.status == 3) {
                return "<a class='layui-btn layui-btn-danger layui-btn-xs'>" + data.status_label + "</a>"
            }
        }


        var pager = layui.grid
            , layarea = layui.layarea
            , laydate = layui.laydate
            , tableId = "drug-table"
            , tableFilter = "drug-table-filter"
            , searchFilter = "drug-search"
            , cols = [
            {width: 60, field: "_serial", title: "序号"},
            {width: 170, field: "number", title: "上报编号", event: "detail", style: "color:blue"},
            {field: "title", title: "药品名称"},
            {field: "category", title: "药品类别"},
            {field: "risk", title: "风险累及系统-器官"},
            {width: 170, field: "reported_at", title: "上报时间", sort: true},
            {field: "unit", title: "上报单位"},
            {field: "address", title: "所属地区"},
            {field: "phone", title: "联系电话"},
            {field: "remark", title: "备注"},
            {width: 170, field: "checked_at", title: "处理时间", sort: true},
            {title: "处理状态", templet: statusinfo},
            {field: "comment", title: "风险评价"},
        ]
        , table = {
            "id": tableId,
            "elem": "#" + tableId,
            "limit": 8,
            "limits": [10, 20, 50, 100],
            "cols": [cols],
            "method": "post",
            "request": {"pageName": "page", "limitName": "per-page"},
            "url": "/report-history",
            "toolbar": "#toolBar",
            "page": {"hash": "fenye"},
            "autoSort": false,
            "defaultToolbar": ["filter", "print", {
                "title": "导出Excel",
                "layEvent": "OUTPUT_EXCEL",
                "icon": "layui-icon-export"
            }]
        }
        , eventOptions = {
            "detail": {"url": "/report-history/view",  "open": "iframe", "openRefresh": true},
            "OUTPUT_EXCEL": {"url": "/report-history/excel", "filename": "药品上报列表"}
        }
        , events = {}

        layarea.render({
            elem: '#' + searchFilter,
            change: function (res) {
                //选择结果
                console.log(res)
            }
        });

        laydate.render({
            elem: '#yak_dt_s',
            trigger: 'click'
        });

        laydate.render({
            elem: '#yak_dt_e',
            trigger: 'click'
        });

        pager.render({
            "searchFilter": searchFilter,
            "tableId": tableId,
            "tableFilter": tableFilter,
            "sort": "server",
            "countCache": true,
            "table": table,
            "editor": {
                "method": "get",
                "url": "/sys/menu/update",
                "select": [{"field": "pid", "data": [{"name": "1", "value": "TTT"}]}]
            },
            "eventOptions": eventOptions
        }, events)
    })
</script>
{% endblock %}